package com.tb.service;

import com.tb.mapper.SensitiveWordMapper;
import com.tb.model.SensitiveWord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 关键字过滤相关服务
 * @author: wangguichun
 * @create: 2018-03-29 09:03
 **/
@Service
public class SensitiveWordService {

    @Autowired
    private SensitiveWordMapper sensitiveWordMapper;

    /**
     * 获取敏感词包装类的列表
     * @return
     */
    public List<SensitiveWord> getWordList() {
        return sensitiveWordMapper.selectByExample(null);
    }

    /**
     * 获取敏感词的字符串列表
     * @return
     */
    public List<String> getStringList(){
        List<SensitiveWord> wordList = getWordList();
        List<String> list = new ArrayList<>();
        for (SensitiveWord sensitiveWord : wordList) {
            list.add(sensitiveWord.getWord());
        }
        return list;
    }

    public int getCount() {
        return sensitiveWordMapper.countByExample(null);
    }

    public void deleteById(Integer id) {
        sensitiveWordMapper.deleteByPrimaryKey(id);
    }

    public void addWord(String word) {
        SensitiveWord sensitiveWord = new SensitiveWord();
        sensitiveWord.setWord(word);
        sensitiveWordMapper.insertSelective(sensitiveWord);
    }
}
